// components/test2/test2.js
Component({
  pageLifetimes:{
    show(){
      console.log('show')
    },hide(){
      console.log('hide')
    },resize(){
      console.log('resize')
    },

  },
  lifetimes:{
    created(){
      console.log('create')
    },attached(){
      console.log('attached')
    },ready(){
      console.log('ready')
    },moved(){
      console.log('moved')
    },detached(){
      console.log('detached')
    },error(){
      console.log('error')
    },
  
  },

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    n1: 0,
    n2: 0,
    sum: 0,
    rgb: {
      r: 0,
      g: 0,
      b: 0
    },
    fullColor: '0,0,0'

  },
  observers: {
    'n1,n2': function (newN1, newN2) {
      console.log(newN1, newN2)
    },
    'rgb.r,rgb.g,rgb.b':function(newR,newG,newB){
      this.setData({
        fullColor:`${newR},${newG},${newB}`
      })
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    addN1() {
      this.setData({
        n1: ++this.data.n1
      })
    },
    addN2() {
      this.setData({
        n2: ++this.data.n2
      })
    },
    changeR(){
      this.setData({
        'rgb.r':this.data.rgb.r + 5 > 255 ? 255:this.data.rgb.r + 5
      })
    },
    changeG(){
      this.setData({
        'rgb.g':this.data.rgb.g + 5 > 255 ? 255:this.data.rgb.g + 5
      })
    },
    changeB(){
      this.setData({
        'rgb.b':this.data.rgb.b + 5 > 255 ? 255:this.data.rgb.b + 5
      })
    },

  }
})